package com.ryskoo.permission.role.repository;

import com.ryskoo.common.constant.CacheConstant;
import com.ryskoo.framework.core.repository.BasicRedisImpl;
import com.ryskoo.framework.core.utils.RedisUtil;
import com.ryskoo.permission.role.domain.RolePO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;
import java.util.List;

@Primary
@Repository
public class RoleRedisImpl extends BasicRedisImpl<RolePO> implements IRoleRepository {

	@Autowired
	private RedisUtil redisClient;

	@Autowired
	private IRoleRepository roleRepository;

	@PostConstruct
	public void init() {
		this.setRedisClient(redisClient);
		this.setDao(roleRepository);
	}

	public RoleRedisImpl() {
		super(CacheConstant.PMS_ROLE_KEY);
	}

	/**
	 * 删除角色信息以及角色与权限的关联关系，支持批量删除
	 *
	 * @param managerId 管理员id {@link String}
	 * @return 管理员拥有的角色列表 {@link List}&lt;{@link RolePO}&gt;
	 */
	@Override
	public List<RolePO> getRoleByManagerId(String managerId) {
		return roleRepository.getRoleByManagerId(managerId);
	}
}
